package com.soboot.handler;

import com.soboot.base.util.ResponseUtil;
import com.soboot.response.Result;
import org.springframework.http.MediaType;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author:
 * @createTime: 2022年09月20日 13:09:59
 * @version:
 * @Description: 自定义拒绝处理
 * @Copyright:
 */
public class BaseAccessDeniedHandler implements AccessDeniedHandler {

    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException {
        ResponseUtil.writeResponse(
                MediaType.APPLICATION_JSON_VALUE,
                HttpServletResponse.SC_FORBIDDEN, Result.fail(HttpServletResponse.SC_FORBIDDEN, "没有权限访问该资源"),response);
    }
}
